#ifndef RMD_DATA_FRAME_H_
#define RMD_DATA_FRAME_H_

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "lane_const_parameter.h"
#include "lane_line_struct.h"
#include <iostream>

namespace rmd {
class DataFrame {
 public:
  DataFrame();
  virtual ~DataFrame();
  void Init(std::string& configFile);

  static DataFrame* getInstance();
  static DataFrame* instance_;

  bool error_code;
  long lIndex;
  //image data
  cv::Mat process_image;
  cv::Mat process_grayimage;

  //auto time
  short Update_Gap;
  short Auto_Frame_Gap;
  short Stable_Num;

  //field lines
  short end_line;
  short middle_start_line;
  short far_line;
  short start_line;

  //boundary
  cv::Point up_boundary;
  cv::Point  left_boundary;
  cv::Point  right_boundary;

  //vanish point
  short x_Length;
  short y_Length;
  cv::Point adapt_vanishing_point;
  cv::Point adapt_vanishing_point_bf;
  cv::Point constant_vanishing_point;
  cv::Point user_vanishing_point;

  //lane width limit
  std::vector<cv::Point2f> lane_width_limit;
  std::vector<float> lane_line_fitting_width;

  //refine
  float refine_lane_width;

  std::vector<int> line_list;
  std::vector<cv::Scalar> scalar_color;

  //atuo calibration
  bool  auto_calibration_flag;
  long  auto_frame_index;
  std::vector<INITLDVP> auto_ld_vps;
  std::vector<INITLDVP> auto_select_ld_vps;

  //save data
    std::vector<LaneLine> pri_detection_results;
    std::vector<LaneLine> pri_refine_results;

    PRILANERESULT pri_lane_result;
    cv::Point virtaul_point[4];
    VirtualCenterLine virtual_center_lines;

    int good_ldw_cout;
    int miss_ldw_cout;

    float show_left_rho;
    float show_right_rho;

//debug
  long debug_picture_index;
  char debug_file_path[kMaxChar];
  char debug_base_dir[kMaxChar];
  bool debug_index;
  bool debug_show_write;

public:
  void Init(std::string& configFile, short width = kImageWidth, short height = kImageHeight);
  bool UpdateInit(int x,int y, bool auto_check = false);

 private:
  void InitScalarColor();
  void GetThresholdValue();
  void CalcLaneFittingWidth(const short* pInitfT_Width, short height,short middle_start_line, short start_line,short end_line);
  std::vector<cv::Point2f> CalcLaneWidthIndex(short height, short endLine, double upLaneInterval, double downLaneInterval,
      short udLineNum, short downLineNo, double downLaneWidthMin,
      double downLaneWidthMax);
  float InitMinLaneWidth();
  bool CheckGenerateLaneWidth(float& lane_width, short location = 1);
  void  InitSelectRoi() ;
  short GetAdapteMaxWidth(short vanishingPointY, short startLine,
                                   short iWidth, short iHeight);

  std::vector<int> GetLineList(int nmFieldLineNum = kPmFeatureNmFiledLineNum);

};
}
#endif
